<?php

/**
 * tracker actions.
 *
 * @package    namasce
 * @subpackage tracker
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class trackerActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
    $this->forward('tracker', 'list');
  }

 /**
  * Executes list action
  *
  * @param sfRequest $request A request object
  */
  public function executeList(sfWebRequest $request)
  {
    $this->plates = PlateTrackerTable::findMy();
  }

  public function executeStart(sfWebRequest $request)
  {
    if (!($userId = myUser::id()) || !$request->isXmlHttpRequest())
    {
      return sfView::NONE;
    }

    try
    {
      $tracker = new PlateTracker();
      $tracker->plate = $request->getParameter('id');
      $tracker->user_id = $userId;
      $tracker->save();
    }
    catch (Exception $e) { }

    return sfView::NONE;
  }

  public function executeStop(sfWebRequest $request)
  {
    if (!($userId = myUser::id()) || !$request->isXmlHttpRequest())
    {
      return sfView::NONE;
    }

    try
    {
      Doctrine_Query::create()->delete('PlateTracker')->where('user_id = ? AND plate = ?')
        ->execute(array($userId, $request->getParameter('id')));
    }
    catch (Exception $e) { }

    return sfView::NONE;
  }
}
